﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.
namespace Abc.Web.Mvc.Areas.HtAdmin.Controllers;

/// <summary>
/// 全球化和本地化
/// </summary>
//[AuthorizePolicy]
[MaMvc( controller: "HtLocalization", controllerDescription: "全球化和本地化", PCode = "HtAdmin_System")]
public class HtLocalizationController : HtAdminBaseController
{
    private readonly ILogger<HtLocalizationController> _logger;
    private readonly IHtLocalizationService _htLocalizationService;
    public HtLocalizationController(ILogger<HtLocalizationController> logger
    , IHtLocalizationService htLocalizationService)
    {
        _logger = logger;
        _htLocalizationService = htLocalizationService;
    }
    /// <summary>
    /// 列表页面
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [MaMenu(name: "全球化和本地化列表", Code = "Index", Url = "", UrlPar = "")]
    [MaPermission(name: "全球化和本地化列表", actions: "Index,GetList")]
    public async Task<IActionResult> Index()
    {
        return View();
    }
    /// <summary>
    /// 获取列表
    /// </summary>
    /// <param name="searchquery">查询条件</param>
    /// <returns></returns>
    [UnifyResult(typeof(JsonResult))]
    [HttpGet, HttpPost]
    public async Task<JsonResult> GetList(HtLocalizationQuery searchquery)
    {
        var pagedlist = await _htLocalizationService.GetAllByPageToLayui(searchquery);
        return Json(pagedlist);
    }
    /// <summary>
    /// 新增
    /// </summary>
    /// <param name="id">ID</param>
    /// <returns></returns>
    [MaPermission(name: "新增", actions: "Add,Edit")]
    public async Task<IActionResult> Add(long? id)
    {
        return View("Info");
    }
    /// <summary>
    /// 详情
    /// </summary>
    /// <param name="id">ID</param>
    /// <returns></returns>
    [MaPermission(name: "编辑", actions: "Info,Edit")]
    public async Task<IActionResult> Info(long? id)
    {
        HtLocalizationOut entity = null;
        if (id.HasValue)
        {
            entity = await _htLocalizationService.Get(id.Value);
        }
        return View(entity ?? new HtLocalizationOut());
    }
    /// <summary>
    /// 编辑
    /// </summary>
    /// <param name="input">提交对象</param>
    /// <returns></returns>
    [HttpPost]
    // [ValidateInput(false)]
    public async Task<JsonResult> Edit(HtLocalizationInput input)
    {
        await _htLocalizationService.Update(input);
        return Json("");
    }
    /// <summary>
    /// 批量删除
    /// </summary>
    /// <param name="ids">需要删除数据，多个英文逗号隔开</param>
    /// <returns></returns>
    [HttpPost]
    [MaPermission(name: "批量删除", actions: "BatchDelete")]
    public async Task<JsonResult> BatchDelete(string ids)
    {
        await _htLocalizationService.BatchDelete(ids);
        return Json("");
    }
    //[HttpPost]
    //[MaPermission(name: "设置状态", actions: "SetState")]
    //public async Task<JsonResult> SetState(long id, bool state, string type)
    //{
    //    await _htLocalizationService.SetState(id, state, type);
    //    return Json("");
    //}
    //[HttpPost]
    //[MaPermission(name: "删除", actions: "Delete")]
    //public async Task<JsonResult> Delete(long id)
    //{
    //    await _htLocalizationService.Delete(id);
    //    return Json("");
    //}
}